﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BullTasDesaDal.Entities;
using NHibernate.Criterion;
using NHibernate.SqlCommand;

namespace BullTasDesaDal.Service
{
    public class LocationService
    {
        public static ICollection<Province> GetAllProvinces()
        {

            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                return session.CreateCriteria(typeof(Province)).List<Province>();

            }

        }

        public static ICollection<Department> GetDepartmentByProvince(short idProvince)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                return session.CreateCriteria(typeof(Department))
                    .CreateAlias("Province", "dProvince", JoinType.InnerJoin)
                    .Add(Restrictions.Eq("dProvince.Id", idProvince))
                    .AddOrder(Order.Asc("Name"))
                    .List<Department>();


            }
        }


        public static ICollection<Locality> GetLocalitysByDepartment(int idDepartment)
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                return session.CreateCriteria(typeof(Locality))
                    .CreateAlias("Department", "lDepartment", JoinType.InnerJoin)
                    .Add(Restrictions.Eq("lDepartment.Id", idDepartment))
                    .AddOrder(Order.Asc("Name"))
                    .List<Locality>();


            }
        }
    }
}
